﻿<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Light">
            <SolidColorBrush x:Key="TextEditorForeground"
                             Color="Black"/>
        </ResourceDictionary>
        <ResourceDictionary x:Key="Dark">
            <SolidColorBrush x:Key="TextEditorForeground"
                             Color="#F0F0F0"/>
        </ResourceDictionary>
        <ResourceDictionary x:Key="HighContrast">
            <SolidColorBrush x:Key="TextEditorForeground"
                             Color="{ThemeResource TextControlForeground}"/>
        </ResourceDictionary>
    </ResourceDictionary.ThemeDictionaries>

    <Style x:Key="TextEditorCore" TargetType="RichEditBox">
        <Setter Property="Foreground" Value="{ThemeResource TextEditorForeground}"/>
        <Setter Property="Background" Value="Transparent"/>
        <!--<Setter Property="ContentLinkForegroundColor" Value="{ThemeResource ContentLinkForegroundColor}"/>
        <Setter Property="ContentLinkBackgroundColor" Value="{ThemeResource ContentLinkBackgroundColor}"/>-->
        <Setter Property="SelectionHighlightColor" Value="{ThemeResource TextControlSelectionHighlightColor}"/>
        <Setter Property="BorderBrush" Value="{ThemeResource TextControlBorderBrush}"/>
        <Setter Property="BorderThickness" Value="0,0,0,0"/>
        <Setter Property="FontFamily" Value="{ThemeResource ContentControlThemeFontFamily}"/>
        <Setter Property="FontSize" Value="{ThemeResource ControlContentThemeFontSize}"/>
        <Setter Property="ScrollViewer.HorizontalScrollMode" Value="Enabled"/>
        <Setter Property="ScrollViewer.VerticalScrollMode" Value="Enabled"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto"/>
        <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False"/>
        <Setter Property="TextWrapping" Value="NoWrap"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="UseSystemFocusVisuals" Value="{ThemeResource IsApplicationFocusVisualKindReveal}"/>
        <!--<Setter Property="ContextFlyout" Value="{StaticResource TextControlCommandBarContextFlyout}"/>
        <Setter Property="SelectionFlyout" Value="{StaticResource TextControlCommandBarSelectionFlyout}"/>-->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RichEditBox">
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto"/>
                            <RowDefinition Height="*"/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Disabled"/>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="PointerOver"/>
                                <VisualState x:Name="Focused"/>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <ContentPresenter
                            x:Name="HeaderContentPresenter"
                            ContentTemplate="{TemplateBinding HeaderTemplate}"
                            Content="{TemplateBinding Header}"
                            FontWeight="Normal"
                            Foreground="{ThemeResource TextControlHeaderForeground}"
                            Margin="{ThemeResource RichEditBoxTopHeaderMargin}"
                            Grid.Row="0"
                            TextWrapping="Wrap"
                            VerticalAlignment="Top"
                            Visibility="Collapsed"
                            x:DeferLoadStrategy="Lazy">
                        </ContentPresenter>
                        <Border
                            x:Name="BorderElement"
                            Background="{TemplateBinding Background}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            CornerRadius="{TemplateBinding CornerRadius}"
                            MinHeight="{ThemeResource TextControlThemeMinHeight}"
                            MinWidth="{ThemeResource TextControlThemeMinWidth}"
                            Grid.Row="1"/>
                        <Grid x:Name="RootGrid" Grid.Row="1">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Name="LineNumberColumnDefinition" Width="Auto"/>
                                <ColumnDefinition x:Name="TextEditorColumnDefinition" Width="*"/>
                            </Grid.ColumnDefinitions>
                            <Canvas x:Name="LineHighlighterAndIndicatorCanvas" Grid.ColumnSpan="2">
                                <Border x:Name="LineIndicator"
                                        BorderBrush="{StaticResource SystemControlForegroundAccentBrush}"
                                        Visibility="Collapsed"/>
                                <Grid x:Name="LineHighlighter"
                                      Background="{ThemeResource SystemControlBackgroundListLowBrush}"
                                      Opacity="0.65"
                                      BorderThickness="0"
                                      Visibility="Collapsed"/>
                            </Canvas>
                            <Grid x:Name="LineNumberGrid" 
                                  Grid.Column="0"
                                  BorderThickness="0,0,0,0"
                                  BorderBrush="{ThemeResource SystemControlBackgroundTransparentRevealBorderBrush}">
                                <Canvas x:Name="LineNumberCanvas"/>
                            </Grid>
                            <Grid Grid.Column="1">
                                <ScrollViewer
                                x:Name="ContentElement"
                                AutomationProperties.AccessibilityView="Raw"
                                HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                HorizontalScrollMode="{TemplateBinding ScrollViewer.HorizontalScrollMode}"
                                IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                                IsHorizontalRailEnabled="{TemplateBinding ScrollViewer.IsHorizontalRailEnabled}"
                                IsTabStop="False"
                                IsVerticalRailEnabled="{TemplateBinding ScrollViewer.IsVerticalRailEnabled}"
                                Margin="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}"
                                VerticalScrollMode="{TemplateBinding ScrollViewer.VerticalScrollMode}"
                                VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                ZoomMode="Disabled"/>
                            </Grid>
                        </Grid>
                        <TextBlock 
                            x:Name="PlaceholderTextContentPresenter"
                            Foreground="{ThemeResource TextControlPlaceholderForeground}"
                            IsHitTestVisible="False"
                            Margin="{TemplateBinding BorderThickness}"
                            Padding="{TemplateBinding Padding}"
                            Grid.Row="1"
                            Text="{TemplateBinding PlaceholderText}"
                            TextWrapping="{TemplateBinding TextWrapping}"
                            TextAlignment="{TemplateBinding TextAlignment}"
                            OpticalMarginAlignment="TrimSideBearings"/>
                        <ContentPresenter
                            x:Name="DescriptionPresenter"
                            AutomationProperties.AccessibilityView="Raw"
                            Content="{TemplateBinding Description}"
                            Foreground="{ThemeResource SystemControlDescriptionTextForegroundBrush}"
                            Grid.Row="2"
                            x:Load="False"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>